package cn.jiyun.controller;


import cn.jiyun.pojo.Stage;
import cn.jiyun.result.PageResult;
import cn.jiyun.result.QueryPageBean;
import cn.jiyun.result.Result;
import cn.jiyun.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("stage")
public class StageController {

    @Autowired
    private StageService stageService;

    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        List<Map> list=stageService.findPage(queryPageBean);
        PageResult result = new PageResult();
        result.setRows(list);
        /*long i=stageService.jilu();
        result.setTotal(i);*/
        return result;
    }

    @RequestMapping("delete")
    public Result delete(Integer sid){
        int i=stageService.delete(sid);
        if (i>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"error");
        }
    }

    @RequestMapping("findById")
    public List<Stage> findById(Integer sid){
       return stageService.findById(sid);
    }

    @RequestMapping("add")
    public Result add(@RequestBody Stage stage){
        int i=stageService.add(stage);
        if (i>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"error");
        }
    }

    @RequestMapping("edit")
    public Result edit(@RequestBody Stage stage){
        int i=stageService.edit(stage);
        if (i>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"error");
        }
    }
}
